package com.leiyuee.springbase.service;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component //implements InitializingBean
public class UserService  {


    @Autowired
    private OrderService orderService;

    // public UserService(OrderService orderService) { //bean对象--> 创建orderService   找的时候 先byType 如果有多个就会 再byName (Autowired注解) 找不到会报错
    //
    //     this.orderService = orderService;
    // }

    public  void  test(){
        System.out.println("123");
        Optional.ofNullable(orderService).ifPresent(OrderService::orderService);

    }

    // todo :1.2  实现InitializingBean接口 让spring来执行你的方法,常用于spring和别的框架做整合
    // @Override
    // public void afterPropertiesSet() throws Exception {
    //     System.out.println("让spring来执行你的方法");
    //     //可以做校验后抛出异常--> 就是这个对象没有创建出来
    // }
}
